package com.zhang.learn.loglearn.slf4j;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhanghaolian
 * @Description TODO
 * @ClassName LearnSlf4j
 * @date 2021/3/21 14:44
 */
public class LearnSlf4j {
    @Test
    public void simpleTest() {
        Logger logger = LoggerFactory.getLogger(this.getClass());

        // slf4j五日志级别，默认打印info以上级别的日志
        logger.error("erro");
        logger.warn("warn");
        logger.info("info");
        logger.debug("debug");
        logger.trace("trace");

        // 使用占位符记录日志信息
        logger.info("变量:{},{}","variable1",15);

        // 异常输出
        try {
            int i = 1/0;
        }catch (Exception exception) {
            logger.error("exception:",exception);
        }

    }

    /**
     * slf4j用log4j作日志实现框架
     * 需要引入 log4j-over-slf4j桥接器 以及 maven依赖
     */
    @Test
    public void testLogWithLog4j() {
        org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(this.getClass());
        logger.info("info");
    }
}
